package com.wkk.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wkk.entity.City;
import com.wkk.service.CityService;

@Controller
@CrossOrigin
@RequestMapping("/city")
public class CityController {
	@Resource
	private CityService cityService;

	@ResponseBody
	@RequestMapping("/list")
	public List<City> list(HttpServletRequest req) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("kingdom_id", req.getParameter("kingdom_id") != null ? req.getParameter("kingdom_id") : null);
		List<City> citys = cityService.list(map);
		return citys;

	}

	@ResponseBody
	@RequestMapping("/save")
	public int save(HttpServletRequest req) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("name", req.getParameter("name") != null ? req.getParameter("name") : null);
		map.put("kingdom_id", req.getParameter("kingdom_id") != null ? req.getParameter("kingdom_id") : null);
		int count = cityService.add(map);
		return count;
	}

	@ResponseBody
	@RequestMapping("/update")
	public int update(HttpServletRequest req) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", req.getParameter("id") != null ? req.getParameter("id") : null);
		map.put("kingdom_id", req.getParameter("kingdom_id") != null ? req.getParameter("kingdom_id") : null);
		int count = cityService.update(map);
		return count;
	}
}
